import unittest
from hm08_db_util import DBUtil

mobile = '11122223456'

class TestEmp(unittest.TestCase):

    def setUp(self) -> None:
        # 删除员工数据
        sql = f"delete from bs_user where `mobile`='{mobile}'"
        DBUtil.iud_data(sql)

    def tearDown(self) -> None:
        # 删除员工数据
        sql = f"delete from bs_user where `mobile`='{mobile}'"
        DBUtil.iud_data(sql)

    def test_add_emp(self):
        # 插入指定手机号的员工
        sql = f"insert into bs_user(`id`, `mobile`, `username`) values('135975000', '{mobile}', 'mikejiang')"
        n = DBUtil.iud_data(sql)
        self.assertEqual(1, n)

        # 查询指定手机号的员工
        sql = f"select `id`, `mobile`, `username` from bs_user where `mobile`='{mobile}'"
        emp_data = DBUtil.query_one(sql)
        self.assertEqual(mobile, emp_data[1])